<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            background: pink;
            height: 200px;
            visibility: hidden;
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <button>点我显示隐藏</button>
    <script>
      var flag =true
        document.querySelector('button').onclick=function(){
             if(flag){
                 document.querySelector('.box').setAttribute('style','visibility:visible')
             }else{
                document.querySelector('.box').setAttribute('style','visibility:hidden')
             }
             flag=!flag
        }
    </script>
</body>
</html>